﻿using GrapeCity.Forguncy.Commands;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static dingtalk_Card.dingtalk_CardServerCommand;

namespace dingtalk_Card
{
    internal class gengxin
    {
        //协作场域信息
        public static AlibabaCloud.SDK.Dingtalkcard_1_0.Models.UpdateCardRequest.UpdateCardRequestCardUpdateOptions gengxinpeizhi(bool aaaa,bool bbbb)
        {
            var cardUpdateOptions = new AlibabaCloud.SDK.Dingtalkcard_1_0.Models.UpdateCardRequest.UpdateCardRequestCardUpdateOptions
            {
                UpdateCardDataByKey = aaaa,
                UpdatePrivateDataByKey = bbbb,
            };
            return cardUpdateOptions;
        }
        //卡片数据内容方法初始化
        public static async Task<AlibabaCloud.SDK.Dingtalkcard_1_0.Models.UpdateCardRequest.UpdateCardRequestCardData> CreateCardData(IServerCommandExecuteContext dataContext, IEnumerable<kuozhan> aaa)
        {
            // 创建一个字典来存储卡片数据内容
            var cardDataCardParamMap = new Dictionary<string, string>();

            // 先检查 数据是否为空
            if (aaa == null || !aaa.Any())
            {
                dingcard. CreateErrorJson(101, "卡片数据内容不能为空");
                return null; // 停止执行
            }


            // 遍历卡片模板内容替换参数列表
            foreach (var param in aaa)
            {
                //对参数内容值做公式计算
                var key = (await dataContext.EvaluateFormulaAsync(param.参数名))?.ToString() ?? string.Empty;
                var value = (await dataContext.EvaluateFormulaAsync(param.参数值))?.ToString() ?? string.Empty;
                // 将参数名和参数值转换为字符串并添加到字典中
                cardDataCardParamMap[key] = value;

            }
            //组装到对象返回
            var cardData = new AlibabaCloud.SDK.Dingtalkcard_1_0.Models.UpdateCardRequest.UpdateCardRequestCardData
            {
                CardParamMap = cardDataCardParamMap,
            };
            return cardData;
        }

    }
}
